package org.me.marble;

import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11;
import javax.microedition.khronos.opengles.GL11Ext;

/**
*
* @author tungi
*/

public class DrawTexture{

    public DrawTexture(){
    }

    public static void drawAsImage(GL10 gl,Texture texture,Vector position,float[] crop){
        //DrawTexture.draw(gl,texture);
        gl.glBindTexture(texture.getType(),texture.getName());

        ((GL11)gl).glTexParameterfv(texture.getType(),GL11Ext.GL_TEXTURE_CROP_RECT_OES,crop,0);
        //params: x,y,z,w,h
        ((GL11Ext)gl).glDrawTexfOES(position.getX(),position.getY(),position.getZ(),
                                    texture.getWidth(),texture.getHeight());
    }

    public static void draw(GL10 gl,Texture texture){
        gl.glBindTexture(texture.getType(),texture.getName());

        gl.glTexParameterf(texture.getType(),GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_LINEAR);
        gl.glTexParameterf(texture.getType(),GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_LINEAR);
        
        gl.glTexImage2D(texture.getType(),0,GL10.GL_RGBA,texture.getWidth(),texture.getHeight(),
                0,GL10.GL_RGBA,GL10.GL_UNSIGNED_BYTE,texture.getData());
    }
}
